package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.form.Schedule.AddScheduleForm;
import com.example.teachingSystem.pojo.form.Schedule.SchedulePageQuery;
import com.example.teachingSystem.pojo.form.Schedule.UpdateScheduleForm;
import com.example.teachingSystem.pojo.vo.ScheduleVo;
import com.example.teachingSystem.service.CourseScheduleService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/schedule")
@Tag(name = "排课模块")
public class ScheduleController {
    @Autowired
    private CourseScheduleService courseScheduleService;

    @PostMapping("one")
    @Operation(summary = "添加课程安排", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addSchedule(@RequestBody @Validated AddScheduleForm addScheduleForm) {
        return courseScheduleService.addSchedule(addScheduleForm);
    }

    @PutMapping("one")
    @Operation(summary = "更新课程安排", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateSchedule(@RequestBody @Validated
                                         UpdateScheduleForm updateScheduleForm) {
        return courseScheduleService.updateSchedule(updateScheduleForm);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "删除课程安排", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteScheduleById(@PathVariable Long id) {
        return courseScheduleService.deleteScheduleById(id);
    }

    @GetMapping("/more/stu/{semesterId}")
    @Operation(summary = "学生获取课程安排", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<ScheduleVo>> getMyCourseScheduleByStu(@PathVariable Long semesterId) {
        return courseScheduleService.getMyCourseScheduleByStu(semesterId);
    }

    @GetMapping("/more/tea/{semesterId}")
    @Operation(summary = "老师获取课程安排", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<ScheduleVo>> getMyCourseScheduleByTea(@PathVariable Long semesterId) {
        return courseScheduleService.getMyCourseScheduleByTea(semesterId);
    }

    @GetMapping("/more")
    @Operation(summary = "管理员获取课程安排", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ScheduleVo> getMyCourseScheduleByTea(SchedulePageQuery schedulePageQuery) {
        return courseScheduleService.getAllCourseSchedule(schedulePageQuery);
    }
}